package com.ibeeking.gmc.global.g.rest.controller.v1;

import com.ibeeking.gmc.global.g.rest.service.IClientService;
import com.ibeeking.gmc.global.service.common.param.OauthClientParam;
import com.ibeeking.gmc.global.service.common.query.ClientPageQuery;
import com.ibeeking.gmc.global.service.common.vo.OauthClientPageVO;
import com.ibeeking.gmc.global.service.common.vo.OauthClientVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName ClientController控制器
 * @Description 授权客户端
 * @Author ibeeking
 * @Date 2021-05-18 10:34
 **/
@RestController
@RequestMapping("/g/oauth2/client/v1")
public class ClientController {

    @Resource
    private IClientService clientServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "分页查询列表")
    @PostMapping(value = "/pageList")
    public Page<OauthClientPageVO> pageList(@RequestBody ClientPageQuery query) {
        return clientServiceImpl.pageList(query);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "新增客户端")
    @PostMapping(value = "/add")
    public OauthClientVO add(@RequestBody @Validated(BaseValidationGroup.Insert.class) OauthClientParam param) {
        return clientServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "修改客户端")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) OauthClientParam param) {
        return clientServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "重置客户端密钥")
    @GetMapping(value = "/reset/{id}")
    public OauthClientVO reset(@PathVariable("id") Long id) {
        return clientServiceImpl.reset(id);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询客户端")
    @GetMapping(value = "/view/{id}")
    public OauthClientVO view(@PathVariable("id") Long id) {
        return clientServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "启用/禁用客户端")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return clientServiceImpl.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除客户端")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return clientServiceImpl.del(id);
    }
}
